import { Injectable } from '@angular/core';
import { Service } from '../../server/server';
import { Router } from '@angular/router';
declare var $: any;

@Injectable()
export class HeaderService {

  constructor(public server: Service, private router: Router) {
    this.load();
    this.loadTabData();
    this.right = $.extend(this.right, this.server.getRight());
  }

  //初始化权限
  public right: any;
  public load() {
    this.right = {
      "home": {},
    "user": {},
    "system": {},
    "goods": {},
    "order": {},
    "gateway": {},
    "root_roles": {},
    "root_user": {},
    "root_privilege": {},
    "root_openPlatform": {},
    "root_system": {},
    "root_storage": {},
    "root_resource": {},
    "root_product": {},
    "root_order": {},
    "root_gateway": {},
    "root_pavmenu": {},
    //用户
    "roles": {},
    "role": {},
    "personal": {},
    "institution": {},
    "privilege": {},
    "effect": {},
    //系统
    "sysconfig": {},
    "register": {},
    "task": {},
    "journal": {},
    "sso": {},
    "database": {},
    "terminal": {},
    "ip-rule": {},
    "scope-authorization": {},
    "application": {},

    //内容
    "content": {},
    "content_product": {},
    "innertext": {},

    //同义词管理
    "synonym": {},

    //主题词管理
    "keyword": {},
    "root_keyword": {},
    "keywordTrial": {},
    "keywordUnreviewed": {},
    "systemTable": {},
    "systemThemeTag": {},
    "systemTableTag": {},

    //系统设置
    "systemPushed": {},
    "systemTemplateTath": {},
    "systemProductType": {},
    "systemInnerindexStyle": {},
    "systemDatabase": {},

    //内容管理
    "contentInnertext": {},
    "contentProduct": {},

    //报表管理
    "report":{},
    "reportInner":{},
    "reportProduct":{},
    "reportCase":{},
    "reportTheme":{},
    "reportUseby":{},

    //标引任务管理 Start
    "indexingTask": {},
    //产品标引任务
    "product": {},
    "productAudit": {},
    "productList": {},
    "productTaskContent": {},
    "productIndexingTask": {},
    //内文标引任务
    "internal":{},
    "internalAudit": {},
    "internalList": {},
    "internalTaskContent": {},
    "internalIndexingTask": {},
    //主题词标引任务
    "themeInternal":{},
    "themeTaskAudit": {},
    "themeTaskList": {},
    "themeTaskContent": {},
    "themeContentIndexing": {},
    //模板管理
    "template":{},
    "templateAttribute": {},
    //项目管理
    "systemProject": {},

    //标引任务管理 End

    }
  }

  index() {
    this.router.navigateByUrl('/home');
    this.right = $.extend(this.right, this.server.getRight());
    if (this.right['home']['view']) {
      this.router.navigateByUrl('/home');//首页
    } else if (this.right['product']['view']) {
      this.productclick();//产品标引任务
    } else if (this.right['internal']['view']) {
      this.internalclick();//内文标引任务
    } else if (this.right['keyword']['view']) {
      this.keywordclick();//主题词管理
    } else if (this.right['synonym']['view']) {
      this.synonymclick();//同义词管理
    } else if (this.right['content']['view']) {
      this.contentclick();//内容管理
    } else if (this.right['report']['view']) {
      this.reportclick();//报表管理
    } else if (this.right['user']['view']) {
      this.userclick();//用户管理
    } else if (this.right['system']['view']) {
      this.systemclick();//系统管理
    } else {
      this.router.navigateByUrl('/home');
    }
  }

  //任务标引管理点击
  indexingtasklist(){
    if (this.right['product']['view'] || this.right['internal']['view'] || this.right['themeInternal']['view'] || this.right['template']['view'] || this.right['templateAttribute']['view'] || this.right['systemProject']['view']) {
      if (this.right['product']['view'] && this.right['productList']['view']) {
        this.router.navigateByUrl('/product/list?taskType=0');//进入产品任务列表
      } else if (this.right['product']['view'] && this.right['productAudit']['view']) {
        this.router.navigateByUrl('/product/audit?taskType=0');//进入产品审核任务
      } else if (this.right['internal']['view'] && this.right['internalList']['view']) {
        this.router.navigateByUrl('/product/list?taskType=1');//进入内文任务列表
      } else if (this.right['internal']['view'] && this.right['internalAudit']['view']) {
        this.router.navigateByUrl('/product/audit?taskType=1');//进入内文审核任务
      } else if (this.right['themeInternal']['view'] && this.right['themeTaskList']['view']) {
        this.router.navigateByUrl('/product/list?taskType=2');//进入主题词任务列表
      } else if (this.right['themeInternal']['view'] && this.right['themeTaskAudit']['view']) {
        this.router.navigateByUrl('/product/audit?taskType=2');//进入主题词审核任务
      } else if (this.right['template']['view']) {
        this.router.navigateByUrl('/system/template');//进入模板管理
      } else if (this.right['templateAttribute']['view']) {
        this.router.navigateByUrl('/system/template_attribute');//进入模板属性管理
      } else if (this.right['systemProject']['view']) {
        this.router.navigateByUrl('/system/project');//进入项目管理
      } else {
        this.router.navigateByUrl('home');
      }
    }
  }

  //产品标引任务导航点击
  productclick() {
    if (this.right['productList']['view']) {
      this.router.navigateByUrl('/product/list?taskType=0');
    } else if (this.right['productAudit']['view']) {
      this.router.navigateByUrl('/product/audit?taskType=0');
    } else {
      this.router.navigateByUrl('/home');
    }
  }
  //内文标引任务导航点击
  internalclick() {
    if (this.right['internalList']['view']) {
      this.router.navigateByUrl('/product/list?taskType=1');
    } else if (this.right['internalAudit']['view']) {
      this.router.navigateByUrl('/product/audit?taskType=1');
    } else {
      this.router.navigateByUrl('/home');
    }
  }
  //主题词标引任务导航点击
  themeInternalclick() {
    if (this.right['themeTaskList']['view']) {
      this.router.navigateByUrl('/product/list?taskType=2');
    } else if (this.right['themeTaskAudit']['view']) {
      this.router.navigateByUrl('/product/audit?taskType=2');
    } else {
      this.router.navigateByUrl('/home');
    }
  }
  //主题词管理导航点击
  keywordclick() {
    if (this.right['root_keyword']['view'] || this.right['systemTable']['view'] || this.right['systemThemeTag']['view'] || this.right['systemTableTag']['view']) {
      if (this.right['root_keyword']['view'] && this.right['keywordTrial']['view']) {
        this.router.navigateByUrl('/keyword/trial');//主题词已审管理
      } else if (this.right['root_keyword']['view'] && this.right['keywordUnreviewed']['view']) {
        this.router.navigateByUrl('/keyword/unreviewed');//主题词未审管理
      } else if (this.right['systemTable']['view']) {
        this.router.navigateByUrl('/system/table');//主题词表管理
      } else if (this.right['systemThemeTag']['view']) {
        this.router.navigateByUrl('/system/theme-tag');//主题词标签管理
      } else if (this.right['systemTableTag']['view']) {
        this.router.navigateByUrl('/system/table-tag');//主题词表标签管理
      } else {
        this.router.navigateByUrl('user/noauthority');
      }
    }
  }
  //同义词管理导航点击
  synonymclick() {
    this.router.navigateByUrl('/synonym');
  }
  //报表管理导航点击
  reportclick() {
    if (this.right['reportProduct']['view']) {
      this.router.navigateByUrl('/report/product');
    } else if (this.right['reportInner']['view']) {
      this.router.navigateByUrl('/report/inner');
    } else if (this.right['reportCase']['view']) {
      this.router.navigateByUrl('/report/case');
    }else if (this.right['reportTheme']['view']) {
      this.router.navigateByUrl('/report/theme');
    }else if (this.right['reportUseby']['view']) {
      this.router.navigateByUrl('/report/useby');
    } else {
      this.router.navigateByUrl('/home');
    }
  }
  //内容管理导航点击
  contentclick() {
    if (this.right['contentInnertext']['view']) {
      this.router.navigateByUrl('/content/product');
    } else if (this.right['contentProduct']['view']) {
      this.router.navigateByUrl('/content/innertext');
    } else {
      this.router.navigateByUrl('/home');
    }
  }
  //用户导航点击
  userclick() {
    if (this.right['root_roles']['view'] || this.right['root_user']['view'] || this.right['root_privilege']['view']) {
      if (this.right['root_roles']['view'] && this.right['roles']['view']) {
        this.router.navigateByUrl('user/roles');
      } else if (this.right['root_roles']['view'] && this.right['role']['view']) {
        this.router.navigateByUrl('user/role');
      } else if (this.right['root_privilege']['view'] && this.right['privilege']['view']) {
        this.router.navigateByUrl('user/privilege');
      } else if (this.right['root_privilege']['view'] && this.right['effect']['view']) {
        this.router.navigateByUrl('user/effect');
      } else {
        this.router.navigateByUrl('user/noauthority');
      }
    }
  }
  //系统导航点击
  systemclick() {
   
    if (this.right['sysconfig']['view']) {
      this.router.navigateByUrl('/system/sysconfig');
    }else if (this.right['systemPushed']['view']) {
      this.router.navigateByUrl('/system/pushed');
    }else if (this.right['systemProductType']['view']) {
      this.router.navigateByUrl('/system/product-type');
    }else if (this.right['systemInnerindexStyle']['view']) {
      this.router.navigateByUrl('/system/innerindex-style');
    }else {
      this.router.navigateByUrl('/home');
    }
  }

  sessionStorageClear() {
    sessionStorage.clear();
  }

  public tabData: Array<any>;
  public loadTabData() {
    this.tabData = [
      { name: "首页", value: "/home" },
      { name: "产品标引任务", value: "/product" },
      { name: "标引任务列表", value: "/product/list" },
      { name: "标引任务审核", value: "/product/audit" },
      { name: "标引任务内容", value: "/product/content" },
      { name: "模板管理", value: "/system/template" },
      { name: "模板属性管理", value: "/system/template_attribute" },
      { name: "内容管理", value: "/content" },
      { name: "产品内容", value: "/content/product" },
      { name: "内文内容", value: "/content/innertext" },
      { name: "标引任务", value: "/internal" },
      { name: "主题词管理", value: "/keyword" },
      { name: "主题词管理已审", value: "/keyword/trial" },
      { name: "主题词管理未审", value: "/keyword/unreviewed" },
      { name: "同义词管理", value: "/synonym" },
      { name: "角色组管理", value: "/user/roles" },
      { name: "角色管理", value: "/user/role" },
      { name: "用户管理", value: "/user/management" },
      { name: "权限管理", value: "/user/privilege" },
      { name: "功能管理", value: "/user/effect" },
      { name: "系统参数管理", value: "/system/sysconfig" },
      { name: "主题词表", value: "/system/table" },
      { name: "产品分类管理", value: "/system/product-type" },
      { name: "推送API管理", value: "/system/pushed" },
      { name: "模板及路径", value: "/system/template-path" },
      { name: "文内标引样式", value: "/system/innerindex-style" },
      { name: "主题词表标签", value: "/system/table-tag" },
      { name: "主题词标签", value: "/system/theme-tag" },
      { name: "数据库工具", value: "/system/database" },
      { name: "项目管理", value: "/system/project" },
      { name: "标引产品列表", value: "/report/product" },
      { name: "标引内文列表", value: "/report/inner" },
      { name: "已结案任务", value: "/report/case" },
      { name: "主题词标引", value: "/report/theme" },
      { name: "用户标引列表", value: "/report/useby" }
    ];
  }



}
